Skip to content

fix(js): make _acf-compatibility.js strict-mode safe#511

Open
faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:fix/460-acf-compatibility-strict-mode
Open

fix(js): make _acf-compatibility.js strict-mode safe#511
faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:fix/460-acf-compatibility-strict-mode

Conversation

@faisalahammad

Copy link
Copy Markdown

The legacy compatibility layer in assets/src/js/_acf-compatibility.js relied on sloppy-mode (non-strict) JavaScript semantics. Two patterns break the moment the module is forced into strict mode (e.g. via an ES module conversion or a bundler default change):

  1. maybe_get() assigned to an undeclared keys variable — a global leak that becomes a ReferenceError under strict mode.
  2. add_action()'s multi-action split used _acf.add_action.apply(this, arguments) to forward the named action parameter — strict mode disables arguments aliasing of named parameters, so the recursive call silently stopped wrapping user callbacks.

Both spots are fixed without behavior change. Static regression tests added under strict-mode safety (regression for #460) in tests/js/compatibility.test.js fail loudly if either pattern returns.

Verification:

  • npm run test:unit — 953/953 pass
  • npm run test:unit -- tests/js/compatibility.test.js — 28/28 pass including 2 new strict-mode tests
  • coderabbit review --agent — 0 findings
  • 3 parallel sub-agents confirmed 0 affected call sites and 0 deprecated patterns
  • Net 5 fewer lint errors vs trunk (the var addition and the removed action = actions[i] reassignment)

Closes #460

Use of AI Tools

Portions of this PR were authored with the assistance of AI tooling. All changes have been reviewed, tested, and verified by a human contributor.

- Declare local `keys` in maybe_get() — was an implicit global that
  throws ReferenceError under strict mode
- Replace `arguments`-forwarding recursion in add_action() multi-action
  split with explicit positional args — strict mode disables
  `arguments` aliasing of named parameters
- Add static regression tests that fail if either pattern returns

Fixes WordPress#460
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props faisalahammad, cbravobernal.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JS: _acf-compatibility.js depends on sloppy-mode semantics (undeclared global, arguments aliasing)

1 participant